/**
 * @file Describe the file Created by Administrator on 2015/5/20.
 */
function CommonUtil() {
    this.getRootPath = function () {
        // 获取当前网址，如： http://localhost:8080/mis/inedx.jsp
        var curWwwPath = window.document.location.href;
        // 获取主机地址之后的目录，如： mis/inedx.jsp
        var pathName = window.document.location.pathname;
        var pos = curWwwPath.indexOf(pathName);
        // 获取主机地址，如： http://localhost:8080
        var localhostPaht = curWwwPath.substring(0, pos);
        // 获取带"/"的项目名，如：/mis
        // var projectName = pathName.substring(0,
        // pathName.substr(1).indexOf('/') + 1);
        // return (localhostPaht + projectName);
        return localhostPaht;
    };

    this.getArgs = function () {
        var args = {};
        var query = location.search.substring(1);

        if (query !== null && String(query) !== '') {
            // 取得查询串
            var pairs = query.split('&');
            // 循环赋值
            for (var i = 0; i < pairs.length; i++) {
                var pos = pairs[i].indexOf('=');
                // 寻找 "name=value"
                if (Number(pos) === -1) {
                    continue;
                }
                var argname = pairs[i].substring(0, pos);// 取出参数名
                var value = pairs[i].substring(pos + 1);// 取出参数值
                value = decodeURIComponent(value);// 解码请求参数值
                args[argname] = value;
            }
        } else {
            args = null;
        }

        return args;
    };

    this.getTotalPages = function (totalRecords, pageSize) {
        return parseInt(totalRecords / pageSize, 10)
            + ((Number(totalRecords % pageSize) === 0) ? 0 : 1);
    };

    this.isOnlyOneLastPage = function (totalRecords, pageSize) {
        return (Number(totalRecords % pageSize) === 1);
    };

    this.sharedata = function (name, value) {
        var top = window.top;
        var cache = top['_CACHE'] || {};
        top['_CACHE'] = cache;

        return value !== undefined ? cache[name] = value : cache[name];
    };

    this.removeData = function (name) {
        var cache = window.top['_CACHE'];
        if (cache && cache[name]) {
            delete cache[name];
        }
    };

    this.removeAllData = function () {
        var cache = window.top['_CACHE'];
        if (cache !== null && cache !== undefined && String(cache) !== '') {
            window.top['_CACHE'] = null;
        }
    };

    this.isEmpty = function (value) {
        return (value === null || value === undefined);
    };

    this.isNotEmpty = function (value) {
        return (value !== null && value !== undefined);
    };

    this.isContainSpace = function (value) {
        return (String(value).indexOf(' ') > -1);
    };
}
